import { Body, Controller, Get, Put, Query, UseGuards } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { RateService } from './rate.service';
import { RateBatchShowDto, RateRatingDto, RateShowByLoginDto } from '@/module/rate/rate.dto';
import { User } from '@/common/auth/user.decorator';
import { UserModel } from '@/module/user/user.model';
import { UserAuthGuard } from '@/common/auth/user-auth.guard';
import { RateShowByLoginResult, RateShowResult } from '@/module/rate/rate.result';

@Controller('/v1/rates')
@ApiTags('评分')
export class RateV1Controller {
  constructor(private readonly rateService: RateService) {}

  @Get('/batch')
  @ApiOperation({ summary: '批量查询评分' })
  @ApiResponse({type: RateShowResult, isArray: true})
  async batchShow(
    @Query() query: RateBatchShowDto,
  ): Promise<RateShowResult[]> {
    const res = await this.rateService.getBatchRate({
      bizUuidList: query.bizUuidList.split(',')
    });
    return res;
  }

  @Get('/by-login')
  @UseGuards(UserAuthGuard)
  @ApiOperation({ summary: '登录后查询评分' })
  @ApiResponse({type: RateShowByLoginResult})
  async showByLogin(
    @Query() query: RateShowByLoginDto,
    @User() user: UserModel,
  ): Promise<RateShowByLoginResult> {
    const res = await this.rateService.showByLogin(query, user);
    return res;
  }

  @Put('/')
  @UseGuards(UserAuthGuard)
  @ApiOperation({ summary: '评分' })
  async rating(
    @Body() body: RateRatingDto,
    @User() user: UserModel,
  ): Promise<void> {
    await this.rateService.rating(body, user);
    return;
  }
}
